<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div >
    <!--表单-->
    <form class="layui-form " lay-filter="updateQuotationForm" style="text-align: center">
        <div class="layui-block">
            <div class="layui-inline">
                <label class="layui-form-label">报告单据</label>
                <div class="layui-input-inline">
                    <input class="layui-input" type="tel" name="costReportId">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">成品编码</label>
                <div class="layui-input-inline">
                    <input  class="layui-input" type="tel" name="finishedProductCode">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">公司账套</label>
                <div class="layui-input-inline" style="width:260px" >
                    <select  name="pkOrgAccount"  lay-filter="updateQuotationPkOrg" id="updatePkOrg">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <button type="submit" class="layui-btn  layui-btn-normal" lay-submit="" lay-filter="accreditUpdateQuotationQueryBut">查询</button>
                </div>
            </div>
        </div>
    </form>
    <!--表格-->
    <div style="margin: 0 auto">
        <table id="updateQuotationTable" lay-filter="updateQuotationTable"></table>
    </div>
    <!-- 树 -->
</div>

<script th:inline="none">

    layui.use(['form','table','layer'],function () {
        var form = layui.form;
       var table= layui.table;
       var layer= layui.layer;
        //为公司账套赋值
        updatePkOrgInit();

        //监听submit按钮
        form.on('submit(accreditUpdateQuotationQueryBut)',function (data) {

            updateQuotationTableInit(table,data.field);
            return false;
        })

        table.on('edit(updateQuotationTable)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data=  commonAjax("post","/costReport/updateCostReport",{"quotation":obj.value,"costReportId":obj.data.costReportId})
           layer.msg(data.msg)
        });

        form.render();//动态加载的页面需要添加此方法进行再次渲染
    })

    //初始化公司账套的组织
    function updatePkOrgInit() {
        var orgs = commonAjax("get","/manage/user/selectallhrorg");
        $.each(orgs,function (index,item) {
            $("#updatePkOrg").append(new Option(item.name,item.pkhrorg))
        })
    }

    //设置成本报告表格父元素的宽高
    $("#updateQuotationTable").parent().css({"width":costsystemFblW,"height":costsystemFblH})
    //成本报告表格数据获取
    function updateQuotationTableInit(table,data) {
        table.render({
            id: 'updateQuotationTableId',
            page:true,
            elem: '#updateQuotationTable' //指定原始表格元素选择器
            ,width:costsystemFblW
           ,height: costsystemFblH //容器高度
            ,url:'/costReport/queryCostReport?pkOrgAccount='+data.pkOrgAccount+"&userName="+data.userName+"&costReportId="+data.costReportId+"&finishedProductCode="+data.finishedProductCode
            ,cols: [[ //表头
                {field: 'userId', title: '申请人Id', width:150,align:'center',hide:true}
                ,{field: 'appointUserId', title: '授权人Id', width:150,align:'center',hide:true}
                ,{field: 'userName', title: '申请人', width:150,align:'center'}
                ,{field: 'costReportId', title: '成本报告单据号',align:'center', width:180}
                ,{field: 'finishedProductCode', title: '成本编码', width:150,align:'center'}
                ,{field: 'costReportDate', title: '日期', width:150,align:'center', sort: true}
                ,{field: 'grossMarginMoney', title: '毛利', width:150,align:'center'}
                ,{field: 'grossMarginRate', title: '毛利润', width:150,align:'center'}
                ,{field: 'quotation', title: '报价单编号', width:200,align:'center',edit:'text'}
                ,{field: 'costReportStatus', title: '状态', width:150,align:'center',templet:function(d) {
                        //审核状态:0未审核 ,1审核通过 ,2审核不通过,3审核中
                        switch (d.costReportStatus) {
                            case 0:
                                return "<span style='color: #92B8B1'>未审核</span>"
                                break;
                            case 1:
                                return "<span style='color: #704fa0'>审核完成</span>"
                                break;
                            case 2:
                                return "<span style='color: #df0000'>拒绝</span>"
                                break;
                            case 3:
                                return "<span style='color: #e68900'>审核中</span>"
                                break;
                        }
                    }}

            ]]
        });
    }

</script>
</body>
</html>